<template>
  <div class="employees">
    <el-card class="btn">
      <el-button type="primary">导入</el-button>
      <el-button type="primary" @click="add">+新增员工</el-button>
    </el-card>
    <el-card>
      <el-table :data="list">
        <el-table-column label="序号">
          <template v-slot="scope">
            <div>
              {{ (page.page - 1) * page.size + scope.$index + 1 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="姓名" prop="username"></el-table-column>
        <el-table-column label="手机号" prop="mobile"></el-table-column>
        <el-table-column label="工号" prop="workNumber"></el-table-column>
        <el-table-column label="聘用形势" prop="formOfEmployment">
          <template v-slot="{ row }">
            <div>
              {{ row.formOfEmployment | formatType }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="部门" prop="departmentName"></el-table-column>
        <el-table-column label="入职时间" prop="timeOfEntry">
          <template v-slot="{ row }">
            <div>
              {{ row.timeOfEntry | formatTime }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="是否在职" prop=""></el-table-column> -->
        <el-table-column label="状态" prop="enableState"></el-table-column>
        <el-table-column label="操作" width="240px" fixed="right">
          <template v-slot="{ row }">
            <div>
              <el-button type="text">转正</el-button>
              <el-button type="text">调岗</el-button>
              <el-button type="text">离职</el-button>
              <el-button type="text">角色</el-button>
              <el-button type="text" @click="del(row)">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <!--  @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"> -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.page"
          :page-sizes="[1, 5, 10, 100, 200, 300, 400]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
        >
        </el-pagination>
      </div>
      <Dialog :isShow.sync="isShow" :getData="getData"></Dialog>
    </el-card>
  </div>
</template>

<script>
// 导入获取员工列表api,删除员工api
import { sysUser, sysUserDel } from '@/api/employees.js'
// 导入新增员工弹框组件
import Dialog from './components/dialog.vue'
export default {
  components: { Dialog },
  data () {
    return {
      isShow: false,
      list: [],
      page: {
        total: 100,
        page: 1,
        size: 10
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
    // 获取员工列表
    async getData () {
      const res = await sysUser(this.page)
      // 存储总条数
      this.page.total = res.data.total
      // 存储列表数据
      this.list = res.data.rows
      console.log('员工列表', res)
    },
    // 页码改变
    handleCurrentChange (page) {
      this.page.page = page
      this.getData()
    },
    // 页容量改变
    handleSizeChange (size) {
      this.page.size = size
      this.page.page = 1
      this.getData()
    },
    // 新增员工
    add () {
      this.isShow = true
    },
    // 删除员工
    del (row) {
      this.$confirm('确认删除此员工吗', '提示').then(async () => {
        await sysUserDel(row.id)
        this.$message.success('删除成功')
        this.handleCurrentChange(1)
      })
      console.log(row)
    }
  }
}
</script>

<style lang="scss" scoped>
.employees {
  padding: 15px;
  .btn {
    text-align: right;
  }
  .page {
    margin-top: 20px;
    text-align: right;
  }
}
</style>
